# -*- coding: utf-8 -*-
"""
@Time ： 2020/7/29 16:40
@Auth ： Mr. JJ_Cloud
@Company ：testingedu.com.cn
@Function ：Class03 Homework
@install： pip install requests
"""
#1.1. 列表，元组用while遍历实现
name_list = ["zhangsan","lisi","wangwu"]
i=0
while i<len(name_list):
    print(name_list[i])
    i += 1

info_tuple = ("zhaoliu",18,1.75)
i=0
while i<len(info_tuple):
    print(info_tuple[i])
    i += 1

def print_line():
    print("-" * 100)
print_line()

#1.2字典四种遍历实现
dict1 = {'a': '1', 'b': '2', 'c': '3'}
for key in dict1:
    print(key+':'+dict1[key])

dict2 = {'a': '4', 'b': '5', 'c': '6'}
for value in dict2.values():
    print(value)

dict3 = {'a': '7', 'b': '8', 'c': '9'}
for kv in dict3.items():
    print(kv)

dict4 = {'a': '10', 'b': '11', 'c': '12'}
for key,value in dict4.items():
    print(key+':'+value)

print_line()

#2. 自己去抓包，把ip接口的返回结果处理为标准json字符串；再使用json库，把字符串转为dict，并打印你所在地区的location
import requests,json
result = requests.get('https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=116.247.111.94&co=&resource_id=6006&t=1595990977375&ie=utf8&oe=gbk&cb=op_aladdin_callback,jQuery1102039848562048643454_1595990950059&format=json&tn=baidu&_=1595990950060')
res = result.text
print(res)
print(res.find('{'))
print(res.rfind('}'))
print("截取:",res[24:390])

js_info = res[24:390]
jsonres = json.loads(js_info)
print(jsonres['data'][0]['location'])